# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Gordian Edenhofer <gordian.edenhofer@gmail.com>

pkgname=routersploit
pkgver=3.4.0
pkgrel=6
pkgdesc='Open-source exploitation framework dedicated to embedded devices'
url='https://github.com/threat9/routersploit'
arch=('any')
license=('BSD')
depends=('python' 'python-future' 'python-requests' 'python-paramiko' 'python-pysnmp' 'python-pycryptodome')
makedepends=('python-setuptools')
checkdepends=('python-pytest' 'python-pytest-forked' 'python-pytest-xdist' 'flake8' 'python-threat9-test-bed')
source=(${pkgname}-${pkgver}.tar.gz::https://github.com/threat9/routersploit/archive/v${pkgver}.tar.gz
        ${pkgname}-py38.patch::https://github.com/threat9/routersploit/commit/47183c74a49f.patch
        ${pkgname}-py39.patch::https://github.com/threat9/routersploit/commit/8c4bc6f79ed6.patch)
sha512sums=('9182598105c4d1c971dc63ac24059469dd1862af204f59994cfc85012091663a85faee4c7c04cce573eef1fa91525b44a3963b8c24460d3b31595c4ef6a6c4e5'
            'b1f81e6bd8bba0a90b3a5bfc57b5ebb690d83e1e404adc49659dffa23c7dbac902815b3a75195902fcf6a4fb7acb1db627f29533d0e8fc60caaaa76f766fb3cb'
            'd05cb52139493e7026e1d8b199b121c8ada563e0a4a277e1f6a1cd9ed3719eb9036c7b8683e151aaa541c49eb965db0822050dc581d5d76e2b1a6278ac00d486')

prepare() {
  cd $pkgname-$pkgver
  patch -Np1 -i ../${pkgname}-py38.patch
  patch -Np1 -i ../${pkgname}-py39.patch

  # Remove failing tests
  rm tests/exploits/misc/miele/test_pg8528_path_traversal.py
  rm tests/exploits/cameras/xiongmai/test_uc_httpd_path_traversal.py
  rm tests/exploits/routers/dlink/test_dns_320l_327l_rce.py
  rm tests/exploits/routers/tplink/test_wdr740nd_wdr740n_path_traversal.py
}

check() {
  cd ${pkgname}-${pkgver}
  make tests
}

package() {
  cd ${pkgname}-${pkgver}

  python setup.py install --prefix=/usr --root="${pkgdir}" --optimize=1
  rm -rf "${pkgdir}"/usr/lib/python*/site-packages/tests
  mv "${pkgdir}/usr/bin/rsf"{.py,}

  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
  cp -r docs/* "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim: ts=2 sw=2 et:
